package io.gps.datatransfer.task;

import io.gps.datatransfer.command.DSGpsCommand;
import io.gps.datatransfer.command.GpsMsg;
import io.gps.datatransfer.utils.SysDef;
import org.apache.log4j.Logger;

public class BatchWork implements Runnable  {

    private static Logger logger = Logger.getLogger(BatchWork.class);

    /**
     * 定时批量处理设备上报的数据，批量分发
     */
    @Override
    public void run() {
        try {
            if(!SysDef.allMsgQuery.isEmpty()){
                for (int i = 0; i <3000 ; i++) {
                    Object tempMsg=SysDef.allMsgQuery.poll();
                    if(tempMsg!=null){
                        GpsMsg gpsMsg= (GpsMsg) tempMsg;
                        String sim=gpsMsg.getSim();
                        if(SysDef.USE_BLACK_LIST){
                            if(SysDef.BLACK_LIST.get(sim)==null){
                                DSGpsCommand.executeOther(gpsMsg);
                            }
                        }else{
                            DSGpsCommand.executeOther(gpsMsg);
                        }
                    }else{
                        i=3001;
                    }
                }
            }
        } catch (Exception ie) {
            logger.error(ie.getMessage(),ie);
        }
    }
}